<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px">
      <el-form :inline="true" :model="filters">
        <el-form-item>
          <el-input v-model="filters.hosname" placeholder="医院名称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="filters.hoscode" placeholder="医院编号"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="getHospitalSets">查询</el-button>
        </el-form-item>
      </el-form>
    </el-col>

    <!--列表-->
    <el-table :data="hospitalSets" highlight-current-row v-loading="listLoading" style="width: 100%">
      <el-table-column type="index" width="60">
      </el-table-column>
      <el-table-column prop="hoscode" label="医院编号" width="130" sortable>
      </el-table-column>
      <el-table-column prop="hosname" label="医院名称" width="150" sortable>
      </el-table-column>
      <el-table-column label="医院logo" width="150" sortable>
        <template scope="scope">
          <img :src="'data:image/jpg;base64,'+ scope.row.logoData" style="width: 90px;height: 70px;">
        </template>
      </el-table-column>
      <el-table-column prop="param.dictName" label="医院等级" width="120" sortable>
      </el-table-column>
      <el-table-column prop="createTime" label="记录创建时间" width="200" sortable>
      </el-table-column>
      <el-table-column prop="status" label="状态" width="110" :formatter="formatStatus" sortable>
      </el-table-column>
      <el-table-column label="操作" width="300" fixed='right'>
        <template scope="scope">
          <router-link :to="'/hospSet/showDetails/'+scope.row.id">
            <el-button icon="el-icon-search" type="success" size="small">查看详情</el-button>
          </router-link>
          <el-button size="small" type="warning" icon="el-icon-lock" @click="lockHospSet(scope.row.id,0)"
            v-if="scope.row.status==1">下线</el-button>
          <el-button size="small" type="info" icon="el-icon-unlock" @click="lockHospSet(scope.row.id,1)"
            v-if="scope.row.status==0">上线</el-button>
          <router-link :to="'/hospSet/department/'+scope.row.hoscode">
            <el-button icon="el-icon-search" type="primary" size="small">查看排班</el-button>
          </router-link>
        </template>
      </el-table-column>
    </el-table>

    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="page"
        :page-size="limit" layout="prev, pager, next, jumper" :total="total" style="float:right">
      </el-pagination>
    </el-col>

  </section>
</template>

<script>
import apiObj from '../../api/hospital/hospitalList'

export default {
  data () {
    return {
      filters: {
        hoscode: '',
        hosname: ''
      },
      hospitalSets: [],
      total: 0,
      page: 1,
      limit: 5,
      listLoading: false,
    }
  },
  methods: {
    formatStatus: function (row, column) {
      return row.status == 1 ? '已上线' : row.status == 0 ? '未上线' : '未知'
    },
    handleCurrentChange (val) {
      this.page = val
      this.getHospitalSets()
    },
    handleSizeChange (val) {
      this.limit = val
      this.getHospitalSets()
    },
    //获取医院设置列表
    getHospitalSets () {
      let para = {
        hosname: this.filters.hosname,
        hoscode: this.filters.hoscode
      }
      this.listLoading = true
      apiObj.getHospitalListPage(this.page, this.limit, para).then(({ data }) => {
        this.total = data.data.totalElements
        this.hospitalSets = data.data.content
        this.listLoading = false
      })
    },
    // 上线和下线的操作
    lockHospSet (id, status) {
      this.$confirm('确认执行该操作吗？', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true

        apiObj.lockHospital(id, status).then((res) => {
          this.listLoading = false
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.getHospitalSets()
        })
      }).catch(() => {
        this.$message('操作取消')
      })
    }
  },
  created () {
    this.getHospitalSets()
  }
}

</script>

<style>
</style>